package com.health.db.dao.user.impl;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.user.IUserCardIssueDao;
import com.health.db.mapper.UserCardIssueMapper;
import com.health.db.model.UserCardIssue;
import com.health.redis.RedisConstants;


/**
 * 卡激活Dao
 * 卡资源表,正常调用不用调用缓存
 * @author YC
 *
 */
public class UserCardIssueDaoImpl  extends ServiceInterface implements IUserCardIssueDao{

	
	 UserCardIssueMapper userCardIssueMapper;
	
	 /**
	  * 密码校验
	  */
	@Override
	public UserCardIssue selectByPasword(String password) {
		// TODO Auto-generated method stub
		getRedisOperatiorLogic();
		// TODO Auto-generated method stub
		String key = RedisConstants.UserCardIssueMapper+":password:"+password ;
		
		Object object = null;
		UserCardIssue userCardIssue = new UserCardIssue();
	
		if (redisOperatiorLogic.isJedisIsConnected()) {
			object = redisOperatiorLogic.readObject(key,getPublicRedisGroupNo("1"));
		}
		if (null != object  ) {
			if (!object.equals("")) {
				userCardIssue = (UserCardIssue) object;
			}
		} else {
		 
			userCardIssue =userCardIssueMapper.selectByPasword(password);
			if (redisOperatiorLogic.isJedisIsConnected()) {
				redisOperatiorLogic.setEx(key, userCardIssue,getOrderRedisGroupNo("1"));
			}
		}
		return userCardIssue;
	}

	/**
	 * record 主键CardID
	 */
	@Override
	public int updateBySelective(UserCardIssue record) {
		// TODO Auto-generated method stub
		getRedisOperatiorLogic();
		String key = RedisConstants.UserCardIssueMapper+":password:"+record.getPassword() ;
		
		int result=userCardIssueMapper.updateBySelective(record);
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			redisOperatiorLogic.deleteObject(key,getOrderRedisGroupNo("1"));
		}
		return result;
	}

	
	
	/***************************************************************************************************************/
	/**
	 * @return the userCardIssueMapper
	 */
	public UserCardIssueMapper getUserCardIssueMapper() {
		return userCardIssueMapper;
	}

	/**
	 * @param userCardIssueMapper the userCardIssueMapper to set
	 */
	public void setUserCardIssueMapper(UserCardIssueMapper userCardIssueMapper) {
		this.userCardIssueMapper = userCardIssueMapper;
	}

}
